/**
 * 
 */
package problema;

import java.util.Vector;


import Jama.Matrix;

/**
 * @author Jose Antonio Gonzalez, Ambrin Chaudhary
 *
 */
public class Utilidades
{
	public static double dist(Matrix m1, Matrix m2)
	{
		double s= 0;
		int n1 = m1.getColumnDimension();
		int n2 = m1.getRowDimension();
		if(n1 > n2)
		{
			double aux = 0;
			double[][] a1 = m1.getArray();
			double[][] a2 = m2.getArray();
			for (int i = 0; i< n1; i++)
			{
				double aux1 = a1[0][i] - a2[0][i];
				aux1 *= aux1;
				aux += aux1;
			}
			s = Math.sqrt(aux);
		}
		else
		{
			double aux = 0;
			double[][] a1 = m1.getArray();
			double[][] a2 = m2.getArray();
			for (int i = 0; i< n2; i++)
			{
				double aux1 = a1[i][0] - a2[i][0];
				aux1 *= aux1;
				aux += aux1;
			}
			s = Math.sqrt(aux);
		}
		
		return s;
	}
	
	public static String matrixToString (Matrix m)
	{
		String s = "";
		for (int i= 0; i<m.getColumnDimension(); i++)
		{
			for (int j = 0; j<m.getRowDimension(); j++)
			{
				s += m.get(j,i)+",";
			}
			
		}
		
		return s;
	}
	
	public static Matrix toMatrix (Vector<Double> v)
	{
		double d[][] = {{}};
		double daux[] = new double[v.size()];
		for(int i = 0; i < v.size(); i++)
		{
			daux[i] = v.get(i);
		}
		d[0] = daux;
		Matrix m = new Matrix(d) ;
		return m;
	}

	public static double norma2alcuadrado(Matrix m1, Matrix m2) {
		double s= 0;
		int n1 = m1.getColumnDimension();
		int n2 = m1.getRowDimension();
		if(n1 > n2)
		{
			double aux = 0;
			double[][] a1 = m1.getArray();
			double[][] a2 = m2.getArray();
			for (int i = 0; i< n1; i++)
			{
				double aux1 = a1[0][i] - a2[0][i];
				aux1 *= aux1;
				aux += aux1;
			}
			s = aux;
		}
		else
		{
			double aux = 0;
			double[][] a1 = m1.getArray();
			double[][] a2 = m2.getArray();
			for (int i = 0; i< n2; i++)
			{
				double aux1 = a1[i][0] - a2[i][0];
				aux1 *= aux1;
				aux += aux1;
			}
			s = aux;
		}
		
		return s;
		
		
		
		/*double dif,acum=0;
		for(int i=1;i<m1.getColumnDimension();i++)
		{
			dif=(Double.parseDouble(m1.get(arg0, i))-(Double.parseDouble(m2.getValor(i))));
			acum=acum+(dif*dif);
		}
		return acum;*/
	}
}
